<!DOCTYPE html>
<html lang="zh - CN">

<head>
    <meta charset="UTF - 8">
    <meta name="viewport" content="width=device - width, initial - scale = 1.0">
    <title>带下拉框计算器</title>
</head>

<body>
    <div id="app">
        <input type="number" v-model="num1">
        <select v-model="operator">
            <option value="+">+</option>
            <option value="-">-</option>
            <option value="*">*</option>
            <option value="/">/</option>
        </select>
        <input type="number" v-model="num2">
        <button @click="calculate">计算</button>
        <p>结果: {{result}}</p>
    </div>
    <script src="../vue.js"></script>
    <script>
        new Vue({
            el: '#app',
            data: {
                num1: '',
                num2: '',
                operator: '+',
                result: 0
            },
            methods: {
                calculate() {
                    if (this.operator == '+') {
                        this.result = parseFloat(this.num1) + parseFloat(this.num2);
                    } else if (this.operator == '-') {
                        this.result = this.num1 - this.num2;
                    } else if (this.operator == '*') {
                        this.result = this.num1 * this.num2;
                    } else if (this.operator == '/') {
                        this.result = this.num1 / this.num2;
                    }
                }
            }
        });
    </script>
</body>

</html>